{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#############in MLia chap04\n",
    "import os \n",
    "os.chdir(\"/home/lab466/pythons/pyMLIA35/Ch04Bayes\")\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "from numpy import * \n",
    "import bayes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['steak',\n",
       " 'take',\n",
       " 'I',\n",
       " 'my',\n",
       " 'please',\n",
       " 'love',\n",
       " 'dog',\n",
       " 'problems',\n",
       " 'help',\n",
       " 'stupid',\n",
       " 'worthless',\n",
       " 'licks',\n",
       " 'food',\n",
       " 'not',\n",
       " 'flea',\n",
       " 'so',\n",
       " 'park',\n",
       " 'maybe',\n",
       " 'him',\n",
       " 'ate',\n",
       " 'buying',\n",
       " 'stop',\n",
       " 'has',\n",
       " 'how',\n",
       " 'mr',\n",
       " 'is',\n",
       " 'to',\n",
       " 'quit',\n",
       " 'dalmation',\n",
       " 'posting',\n",
       " 'cute',\n",
       " 'garbage']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "##P59\n",
    "#1 准备数据：从文本中构建词向量\n",
    "#先设计一个词表到向量的转换函数\n",
    "#def loadDataSet():\n",
    "#def createVocabList(dataSet):\n",
    "#def bagOfWords2VecMN\n",
    "#def setOfWords2Vec(vocabList, inputSet):\n",
    "#输入为词汇表和文件，输出为文档向量\n",
    " \n",
    "listOPosts,listClasses = bayes.loadDataSet()\n",
    "## \n",
    "myVocabList = bayes.createVocabList(listOPosts)\n",
    "## \n",
    "myVocabList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 0,\n",
       " 1,\n",
       " 0,\n",
       " 1]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## \n",
    "bayes.setOfWords2Vec(myVocabList, listOPosts[0])\n",
    "## \n",
    "bayes.setOfWords2Vec(myVocabList, listOPosts[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#2 训练算法：从词向量计算概率\n",
    "#P61从词向量计算概率\n",
    "#计算每个类别的条件概率\n",
    "#def trainNB0(trainMatrix,trainCategory):\n",
    "#输入为文档矩阵trainMatrix 和\n",
    "#文档类别标签组成的向量trainCategory\n",
    "\n",
    "#3 测试算法\n",
    "#P61  测试朴素贝叶斯方法\n",
    "from numpy import *\n",
    "## \n",
    "##reload(bayes)\n",
    "## \n",
    "listOPosts,listClasses = bayes.loadDataSet()\n",
    "## \n",
    "myVocabList = bayes.createVocabList(listOPosts)\n",
    "## \n",
    "trainMat=[]\n",
    "## \n",
    "for postinDoc in listOPosts:\n",
    "    trainMat.append(bayes.setOfWords2Vec(myVocabList, postinDoc))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-3.04452244, -2.35137526, -3.04452244, -3.04452244, -3.04452244,\n",
       "       -3.04452244, -1.94591015, -3.04452244, -3.04452244, -1.65822808,\n",
       "       -1.94591015, -3.04452244, -2.35137526, -2.35137526, -3.04452244,\n",
       "       -3.04452244, -2.35137526, -2.35137526, -2.35137526, -3.04452244,\n",
       "       -2.35137526, -2.35137526, -3.04452244, -3.04452244, -3.04452244,\n",
       "       -3.04452244, -2.35137526, -2.35137526, -3.04452244, -2.35137526,\n",
       "       -3.04452244, -2.35137526])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "##P61函数返回两个向量和一个概率 \n",
    "p0V,p1V,pAb=bayes.trainNB0(trainMat,listClasses)\n",
    "## \n",
    "pAb\n",
    "## \n",
    "p0V\n",
    "## \n",
    "p1V"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['love', 'my', 'dalmation'] classified as: 0\n",
      "['stupid', 'garbage'] classified as: 1\n"
     ]
    }
   ],
   "source": [
    "##4 P63修改分类器\n",
    "#定义朴素贝叶斯分类函数\n",
    "#def classifyNB(vec2Classify, p0Vec, p1Vec, pClass1):\n",
    "\n",
    "##reload(bayes)\n",
    "##\n",
    "bayes.testingNB()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['This',\n",
       " 'book',\n",
       " 'is',\n",
       " 'the',\n",
       " 'best',\n",
       " 'book',\n",
       " 'on',\n",
       " 'Python',\n",
       " 'or',\n",
       " 'M.L.',\n",
       " 'I',\n",
       " 'have',\n",
       " 'ever',\n",
       " 'laid',\n",
       " 'eyes',\n",
       " 'upon.']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "\n",
    "#P64 贝叶斯实例：使用朴素贝叶斯过滤垃圾邮件\n",
    "## 1 切分文本，将长字符串切分成词表\n",
    "#def textParse(bigString):#\n",
    "mySent='This book is the best book on Python or M.L. I have ever laid eyes upon.'\n",
    "## \n",
    "mySent.split()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/lab466/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:6: FutureWarning: split() requires a non-empty pattern match.\n",
      "  \n",
      "/home/lab466/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:18: FutureWarning: split() requires a non-empty pattern match.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['Hello',\n",
       " 'Since',\n",
       " 'you',\n",
       " 'are',\n",
       " 'an',\n",
       " 'owner',\n",
       " 'of',\n",
       " 'at',\n",
       " 'least',\n",
       " 'one',\n",
       " 'Google',\n",
       " 'Groups',\n",
       " 'group',\n",
       " 'that',\n",
       " 'uses',\n",
       " 'the',\n",
       " 'customized',\n",
       " 'welcome',\n",
       " 'message',\n",
       " 'pages',\n",
       " 'or',\n",
       " 'files',\n",
       " 'we',\n",
       " 'are',\n",
       " 'writing',\n",
       " 'to',\n",
       " 'inform',\n",
       " 'you',\n",
       " 'that',\n",
       " 'we',\n",
       " 'will',\n",
       " 'no',\n",
       " 'longer',\n",
       " 'be',\n",
       " 'supporting',\n",
       " 'these',\n",
       " 'features',\n",
       " 'starting',\n",
       " 'February',\n",
       " '2011',\n",
       " 'We',\n",
       " 'made',\n",
       " 'this',\n",
       " 'decision',\n",
       " 'so',\n",
       " 'that',\n",
       " 'we',\n",
       " 'can',\n",
       " 'focus',\n",
       " 'on',\n",
       " 'improving',\n",
       " 'the',\n",
       " 'core',\n",
       " 'functionalities',\n",
       " 'of',\n",
       " 'Google',\n",
       " 'Groups',\n",
       " 'mailing',\n",
       " 'lists',\n",
       " 'and',\n",
       " 'forum',\n",
       " 'discussions',\n",
       " 'Instead',\n",
       " 'of',\n",
       " 'these',\n",
       " 'features',\n",
       " 'we',\n",
       " 'encourage',\n",
       " 'you',\n",
       " 'to',\n",
       " 'use',\n",
       " 'products',\n",
       " 'that',\n",
       " 'are',\n",
       " 'designed',\n",
       " 'specifically',\n",
       " 'for',\n",
       " 'file',\n",
       " 'storage',\n",
       " 'and',\n",
       " 'page',\n",
       " 'creation',\n",
       " 'such',\n",
       " 'as',\n",
       " 'Google',\n",
       " 'Docs',\n",
       " 'and',\n",
       " 'Google',\n",
       " 'Sites',\n",
       " 'For',\n",
       " 'example',\n",
       " 'you',\n",
       " 'can',\n",
       " 'easily',\n",
       " 'create',\n",
       " 'your',\n",
       " 'pages',\n",
       " 'on',\n",
       " 'Google',\n",
       " 'Sites',\n",
       " 'and',\n",
       " 'share',\n",
       " 'the',\n",
       " 'site',\n",
       " 'http',\n",
       " 'www',\n",
       " 'google',\n",
       " 'com',\n",
       " 'support',\n",
       " 'sites',\n",
       " 'bin',\n",
       " 'answer',\n",
       " 'py',\n",
       " 'hl',\n",
       " 'en',\n",
       " 'answer',\n",
       " '174623',\n",
       " 'with',\n",
       " 'the',\n",
       " 'members',\n",
       " 'of',\n",
       " 'your',\n",
       " 'group',\n",
       " 'You',\n",
       " 'can',\n",
       " 'also',\n",
       " 'store',\n",
       " 'your',\n",
       " 'files',\n",
       " 'on',\n",
       " 'the',\n",
       " 'site',\n",
       " 'by',\n",
       " 'attaching',\n",
       " 'files',\n",
       " 'to',\n",
       " 'pages',\n",
       " 'http',\n",
       " 'www',\n",
       " 'google',\n",
       " 'com',\n",
       " 'support',\n",
       " 'sites',\n",
       " 'bin',\n",
       " 'answer',\n",
       " 'py',\n",
       " 'hl',\n",
       " 'en',\n",
       " 'answer',\n",
       " '90563',\n",
       " 'on',\n",
       " 'the',\n",
       " 'site',\n",
       " 'If',\n",
       " 'you抮e',\n",
       " 'just',\n",
       " 'looking',\n",
       " 'for',\n",
       " 'a',\n",
       " 'place',\n",
       " 'to',\n",
       " 'upload',\n",
       " 'your',\n",
       " 'files',\n",
       " 'so',\n",
       " 'that',\n",
       " 'your',\n",
       " 'group',\n",
       " 'members',\n",
       " 'can',\n",
       " 'download',\n",
       " 'them',\n",
       " 'we',\n",
       " 'suggest',\n",
       " 'you',\n",
       " 'try',\n",
       " 'Google',\n",
       " 'Docs',\n",
       " 'You',\n",
       " 'can',\n",
       " 'upload',\n",
       " 'files',\n",
       " 'http',\n",
       " 'docs',\n",
       " 'google',\n",
       " 'com',\n",
       " 'support',\n",
       " 'bin',\n",
       " 'answer',\n",
       " 'py',\n",
       " 'hl',\n",
       " 'en',\n",
       " 'answer',\n",
       " '50092',\n",
       " 'and',\n",
       " 'share',\n",
       " 'access',\n",
       " 'with',\n",
       " 'either',\n",
       " 'a',\n",
       " 'group',\n",
       " 'http',\n",
       " 'docs',\n",
       " 'google',\n",
       " 'com',\n",
       " 'support',\n",
       " 'bin',\n",
       " 'answer',\n",
       " 'py',\n",
       " 'hl',\n",
       " 'en',\n",
       " 'answer',\n",
       " '66343',\n",
       " 'or',\n",
       " 'an',\n",
       " 'individual',\n",
       " 'http',\n",
       " 'docs',\n",
       " 'google',\n",
       " 'com',\n",
       " 'support',\n",
       " 'bin',\n",
       " 'answer',\n",
       " 'py',\n",
       " 'hl',\n",
       " 'en',\n",
       " 'answer',\n",
       " '86152',\n",
       " 'assigning',\n",
       " 'either',\n",
       " 'edit',\n",
       " 'or',\n",
       " 'download',\n",
       " 'only',\n",
       " 'access',\n",
       " 'to',\n",
       " 'the',\n",
       " 'files',\n",
       " 'you',\n",
       " 'have',\n",
       " 'received',\n",
       " 'this',\n",
       " 'mandatory',\n",
       " 'email',\n",
       " 'service',\n",
       " 'announcement',\n",
       " 'to',\n",
       " 'update',\n",
       " 'you',\n",
       " 'about',\n",
       " 'important',\n",
       " 'changes',\n",
       " 'to',\n",
       " 'Google',\n",
       " 'Groups',\n",
       " '']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## \n",
    "import re\n",
    "## \n",
    "regEx = re.compile('\\\\W*')\n",
    "## \n",
    "listOfTokens = regEx.split(mySent)\n",
    "## \n",
    "listOfTokens\n",
    "## \n",
    "[tok for tok in listOfTokens if len(tok) > 0]\n",
    "\n",
    "## \n",
    "[tok.lower() for tok in listOfTokens if len(tok) > 0]\n",
    "\n",
    "## \n",
    "emailText = open('email/ham/6.txt').read()\n",
    "## \n",
    "listOfTokens=regEx.split(emailText)\n",
    "listOfTokens"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the error rate is: 0.2\n",
      "the error rate is: 0.3\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/lab466/anaconda3/lib/python3.6/re.py:212: FutureWarning: split() requires a non-empty pattern match.\n",
      "  return _compile(pattern, flags).split(string, maxsplit)\n"
     ]
    }
   ],
   "source": [
    "#2 使用朴素贝叶斯进行垃圾邮件分类\n",
    "\n",
    "#垃圾邮件测试函数\n",
    "#def spamTest(): \n",
    "## \n",
    "bayes.spamTest()\n",
    "## 计算10次求平均值\n",
    "bayes.spamTest()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#P68 实例：使用朴素贝叶斯分类器从个人广告中获取区域倾向\n",
    "#将分别从美国的两个城市中选取一些人，\n",
    "#通过分析这些人发布的征婚广告信息，\n",
    "#来比较这两个城市的人们在广告用词上是否不同 。\n",
    "\n",
    "##download feedparser.zip and install it with \"python setup.py install\"\n",
    "## 使用Craglist上的个人广告数据\n",
    "import feedparser\n",
    "##\n",
    "ny=feedparser.parse('https://newyork.craigslist.org/search/stn/sss?format=rss')\n",
    "#ny=feedparser.parse('indexNY.rss')\n",
    "## 访问条目的列表\n",
    "ny['entries']\n",
    "## \n",
    "len(ny['entries'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "## RSS源分类器及高频词去除函数\n",
    "#def calcMostFreq(vocabList,fullText)\n",
    "#def localWords(feed1,feed0):\n",
    "import bayes\n",
    "##reload(bayes)\n",
    "##\n",
    "ny=feedparser.parse('https://newyork.craigslist.org/search/stn/sss?format=rss')\n",
    "#ny=feedparser.parse('indexNY.rss')\n",
    "##\n",
    "sf=feedparser.parse('https://sfbay.craigslist.org/search/stn/sss?format=rss')\n",
    "#sf=feedparser.parse('indexSF.rss')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the word: parting out a 1999 honda accord. 4 cylinder vtec. automatic. do not te is not in my Vocabulary!\n",
      "the word: , never used steel reinforced bed frame foundation w/upholstered grey head-board. \n",
      "see link below for item details. originally $249, on sale at amazon for $204 and being sold for $124. \n",
      "https://www.amazon.com/zinus-upholstered-stitched-pla ... is not in my Vocabulary!\n",
      "the word:  - never used \n",
      "if you're looking for a e is not in my Vocabulary!\n",
      "the word: cellent masticating juicer. this is the one. \n",
      "tribest green star elite juicer \n",
      "more minerals in optimal bioavailability! \n",
      "bio-magnets have been integrated into the green star elite juicer's ... is not in my Vocabulary!\n",
      "the word: i am selling seasonal farm bo is not in my Vocabulary!\n",
      "the word: used once in e is not in my Vocabulary!\n",
      "the word: ify heavy metals and chemicals from the body, including bpa. \n",
      "burn calories and lose weight. \n",
      "​speed healing of injuries  ... is not in my Vocabulary!\n",
      "the word: t 707.299.774nine \n",
      "thanks for looking at \n",
      "www.thecontainercity.com \n",
      "#storage \n",
      "#ship ... is not in my Vocabulary!\n",
      "the word: parting out a 2002 honda accord coupe 6 cylinder automatic. call for information and availability and pricing on parts. selling parts only. call 732-639-oo63. calls only is not in my Vocabulary!\n",
      "the word: parting out a 2002 honda accord four-cylinder automatic. call for information and availability and pricing on parts. selling parts only. call 732-639-oo63. calls only is not in my Vocabulary!\n",
      "the word: vintage collection of board games \n",
      "some classics: \n",
      "carmen san diego (still sealed) \n",
      "trivial pursuit mastergame genius edition \n",
      "trivial pursuit baby boomer edition \n",
      "scrabble \n",
      "battleship \n",
      "yahtzee x2 \n",
      "great family fun \n",
      "$25 cash firm for all \n",
      "meet in seb ... is not in my Vocabulary!\n",
      "the word: it still has 1 year warranty on it bumper to bumper 2020 venom kpm200 | 200cc fuel-injected motorcycle | 6-speed i will te is not in my Vocabulary!\n",
      "the word: 4 4runner the door code is a340h \n",
      "the torque converter and auto trans is included along with the transfer case. \n",
      "$100 or best reasonable offer. as is where is. \n",
      "i ... is not in my Vocabulary!\n",
      "the word: t me \n",
      "i’m in vacaville \n",
      "ben is not in my Vocabulary!\n",
      "the word: 4 sale a 1989 freightliner 3 axle water truck ,air ride rears, cat 3406bw/ jake, 9 speed trans, 4000 gal stainless tank for potable water with stainless pump and plumbing, the truck is getting new rear drivers , the truck is in non op at this time an ... is not in my Vocabulary!\n",
      "the word: little tikes perfect fit 4-in-1 trike \n",
      "this is used in good condition, there are some scuffs and scratches from normal use, see all my pic's for a better look \n",
      "the perfect fit 4-in-1 trike is ready to grow with your child! with all of the features of ... is not in my Vocabulary!\n",
      "the word: stunning and rare!!! \n",
      "*2010 ferrari 599 gtb with full factory hgte package ($30k option) \n",
      "*rosso scuderia over nero interior \n",
      "*$368,900 original msrp \n",
      "*hgte (handling grand turismo evoluzione) package which includes upgraded springs; re-tuned transa is not in my Vocabulary!\n",
      "the word: offering coding services for bmw vehicles that allows owner to take full advantage of their intelligent vehicle. bmw's are powerful machines and they have the greatest tech, however, the settings for these are limited by bmw themselves. i can help yo ... is not in my Vocabulary!\n",
      "the word: full vehicle history report by autocheck. price is $10. just need your email and vin #. instant email delivery. is not in my Vocabulary!\n",
      "the word: clean fill dirt $10 a yard delivered \n",
      "thousands of yards available \n",
      "call or te is not in my Vocabulary!\n",
      "the word: t \n",
      "469 \n",
      "two one five \n",
      "5206 is not in my Vocabulary!\n",
      "the word: item specifics \n",
      "condition: seller refurbished: \n",
      "brand: lenovo \n",
      "ssd capacity: 120 gb ssd processor: intel core 2 duo \n",
      "features: 10/100 lan card, wi-fi model: lenovo thinkpad r60 \n",
      "color: black \n",
      "hard drive capacity: 120gb \n",
      "ram 2.5 gb \n",
      "most suitable for: ... is not in my Vocabulary!\n",
      "the word: mini fridge that’s more medium size. it does work but not always and i’m not good at fi is not in my Vocabulary!\n",
      "the word: $997 geoff lawton permaculture course, new never used. 18 dvd factory sealed set plus 6 bonus dvd's, and \"permaculture - a designers manual\" by bill mollison, new never used. is not in my Vocabulary!\n",
      "the word: clean fill dirt $10 a yard delivered \n",
      "thousands of yards available \n",
      "call or te is not in my Vocabulary!\n",
      "the word: t \n",
      "469 \n",
      "two one five \n",
      "5206 is not in my Vocabulary!\n",
      "the word: concrete pieces useful for retaining wall. appro is not in my Vocabulary!\n",
      "the word: sf &amp; oakland stores operated 1912 - 1960 * measures 9\"  is not in my Vocabulary!\n",
      "the word: 2008 hyundai engine 2.0l (non turbo) \n",
      "124k runs perfect is not in my Vocabulary!\n",
      "the word: asking price is $550 (cash) \n",
      "delivery is possible at an additional fee ($25 flat fee) \n",
      "do you spend long hours at the desk? do you suffer from back or neck pain? are you constantly shifting your body in your current desk chair? you've got to try the  ... is not in my Vocabulary!\n",
      "the word: good condition - this is all solid wood furniture. \n",
      "mattress is included. \n",
      "smoke and pet free home. \n",
      "5 piece - queen sleigh bedroom set. color is a brownish \n",
      "qty 1 queen bed \n",
      "w 62 1/2 \n",
      "l 84 1/2 \n",
      "bed top piece 66” high \n",
      "bottom piece 32” high \n",
      "qty  ... is not in my Vocabulary!\n",
      "the word: widescreen satellite c55-a5245 with dvd windows10 good battery and optical mouse. includes toshiba charger. hd “true bright” display. intel i3-2.40ghz, 4.0gb memory \n",
      "hdmi our, usb3, ethernet and svga connectors. very clean is not in my Vocabulary!\n",
      "the error rate is:  0.6\n",
      "the word: clean fill dirt $10 a yard delivered \n",
      "thousands of yards available \n",
      "call or te is not in my Vocabulary!\n",
      "the word: t \n",
      "469 \n",
      "two one five \n",
      "5206 is not in my Vocabulary!\n",
      "the word: parting out a 1999 honda accord. 4 cylinder vtec. automatic. do not te is not in my Vocabulary!\n",
      "the word: good condition - this is all solid wood furniture. \n",
      "mattress is included. \n",
      "smoke and pet free home. \n",
      "5 piece - queen sleigh bedroom set. color is a brownish \n",
      "qty 1 queen bed \n",
      "w 62 1/2 \n",
      "l 84 1/2 \n",
      "bed top piece 66” high \n",
      "bottom piece 32” high \n",
      "qty  ... is not in my Vocabulary!\n",
      "the word: $997 geoff lawton permaculture course, new never used. 18 dvd factory sealed set plus 6 bonus dvd's, and \"permaculture - a designers manual\" by bill mollison, new never used. is not in my Vocabulary!\n",
      "the word:  - never used \n",
      "if you're looking for a e is not in my Vocabulary!\n",
      "the word: cellent masticating juicer. this is the one. \n",
      "tribest green star elite juicer \n",
      "more minerals in optimal bioavailability! \n",
      "bio-magnets have been integrated into the green star elite juicer's ... is not in my Vocabulary!\n",
      "the word: i am selling seasonal farm bo is not in my Vocabulary!\n",
      "the word: used once in e is not in my Vocabulary!\n",
      "the word: ify heavy metals and chemicals from the body, including bpa. \n",
      "burn calories and lose weight. \n",
      "​speed healing of injuries  ... is not in my Vocabulary!\n",
      "the word: t 707.299.774nine \n",
      "thanks for looking at \n",
      "www.thecontainercity.com \n",
      "#storage \n",
      "#ship ... is not in my Vocabulary!\n",
      "the word: parting out a 2002 honda accord coupe 6 cylinder automatic. call for information and availability and pricing on parts. selling parts only. call 732-639-oo63. calls only is not in my Vocabulary!\n",
      "the word: 2008 hyundai engine 2.0l (non turbo) \n",
      "124k runs perfect is not in my Vocabulary!\n",
      "the word: vintage collection of board games \n",
      "some classics: \n",
      "carmen san diego (still sealed) \n",
      "trivial pursuit mastergame genius edition \n",
      "trivial pursuit baby boomer edition \n",
      "scrabble \n",
      "battleship \n",
      "yahtzee x2 \n",
      "great family fun \n",
      "$25 cash firm for all \n",
      "meet in seb ... is not in my Vocabulary!\n",
      "the word: concrete pieces useful for retaining wall. appro is not in my Vocabulary!\n",
      "the word: 4 4runner the door code is a340h \n",
      "the torque converter and auto trans is included along with the transfer case. \n",
      "$100 or best reasonable offer. as is where is. \n",
      "i ... is not in my Vocabulary!\n",
      "the word: t me \n",
      "i’m in vacaville \n",
      "ben is not in my Vocabulary!\n",
      "the word: 4 sale a 1989 freightliner 3 axle water truck ,air ride rears, cat 3406bw/ jake, 9 speed trans, 4000 gal stainless tank for potable water with stainless pump and plumbing, the truck is getting new rear drivers , the truck is in non op at this time an ... is not in my Vocabulary!\n",
      "the word: stunning and rare!!! \n",
      "*2010 ferrari 599 gtb with full factory hgte package ($30k option) \n",
      "*rosso scuderia over nero interior \n",
      "*$368,900 original msrp \n",
      "*hgte (handling grand turismo evoluzione) package which includes upgraded springs; re-tuned transa is not in my Vocabulary!\n",
      "the word: offering coding services for bmw vehicles that allows owner to take full advantage of their intelligent vehicle. bmw's are powerful machines and they have the greatest tech, however, the settings for these are limited by bmw themselves. i can help yo ... is not in my Vocabulary!\n",
      "the word: , never used steel reinforced bed frame foundation w/upholstered grey head-board. \n",
      "see link below for item details. originally $249, on sale at amazon for $204 and being sold for $124. \n",
      "https://www.amazon.com/zinus-upholstered-stitched-pla ... is not in my Vocabulary!\n",
      "the word: full vehicle history report by autocheck. price is $10. just need your email and vin #. instant email delivery. is not in my Vocabulary!\n",
      "the word: mini fridge that’s more medium size. it does work but not always and i’m not good at fi is not in my Vocabulary!\n",
      "the word: parting out a 2002 honda accord four-cylinder automatic. call for information and availability and pricing on parts. selling parts only. call 732-639-oo63. calls only is not in my Vocabulary!\n",
      "the word: it still has 1 year warranty on it bumper to bumper 2020 venom kpm200 | 200cc fuel-injected motorcycle | 6-speed i will te is not in my Vocabulary!\n",
      "the word: asking price is $550 (cash) \n",
      "delivery is possible at an additional fee ($25 flat fee) \n",
      "do you spend long hours at the desk? do you suffer from back or neck pain? are you constantly shifting your body in your current desk chair? you've got to try the  ... is not in my Vocabulary!\n",
      "the word: sf &amp; oakland stores operated 1912 - 1960 * measures 9\"  is not in my Vocabulary!\n",
      "the word: clean fill dirt $10 a yard delivered \n",
      "thousands of yards available \n",
      "call or te is not in my Vocabulary!\n",
      "the word: t \n",
      "469 \n",
      "two one five \n",
      "5206 is not in my Vocabulary!\n",
      "the word: item specifics \n",
      "condition: seller refurbished: \n",
      "brand: lenovo \n",
      "ssd capacity: 120 gb ssd processor: intel core 2 duo \n",
      "features: 10/100 lan card, wi-fi model: lenovo thinkpad r60 \n",
      "color: black \n",
      "hard drive capacity: 120gb \n",
      "ram 2.5 gb \n",
      "most suitable for: ... is not in my Vocabulary!\n",
      "the word: widescreen satellite c55-a5245 with dvd windows10 good battery and optical mouse. includes toshiba charger. hd “true bright” display. intel i3-2.40ghz, 4.0gb memory \n",
      "hdmi our, usb3, ethernet and svga connectors. very clean is not in my Vocabulary!\n",
      "the word: little tikes perfect fit 4-in-1 trike \n",
      "this is used in good condition, there are some scuffs and scratches from normal use, see all my pic's for a better look \n",
      "the perfect fit 4-in-1 trike is ready to grow with your child! with all of the features of ... is not in my Vocabulary!\n",
      "the error rate is:  0.5\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/lab466/anaconda3/lib/python3.6/re.py:212: FutureWarning: split() requires a non-empty pattern match.\n",
      "  return _compile(pattern, flags).split(string, maxsplit)\n"
     ]
    }
   ],
   "source": [
    "## \n",
    "vocabList,pSF,pNY=bayes.localWords(ny,sf)\n",
    "## \n",
    "vocabList,pSF,pNY=bayes.localWords(ny,sf)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the word: sf &amp; oakland stores operated 1912 - 1960 * measures 9\"  is not in my Vocabulary!\n",
      "the word: clean fill dirt $10 a yard delivered \n",
      "thousands of yards available \n",
      "call or te is not in my Vocabulary!\n",
      "the word: t \n",
      "469 \n",
      "two one five \n",
      "5206 is not in my Vocabulary!\n",
      "the word: parting out a 1999 honda accord. 4 cylinder vtec. automatic. do not te is not in my Vocabulary!\n",
      "the word: widescreen satellite c55-a5245 with dvd windows10 good battery and optical mouse. includes toshiba charger. hd “true bright” display. intel i3-2.40ghz, 4.0gb memory \n",
      "hdmi our, usb3, ethernet and svga connectors. very clean is not in my Vocabulary!\n",
      "the word: good condition - this is all solid wood furniture. \n",
      "mattress is included. \n",
      "smoke and pet free home. \n",
      "5 piece - queen sleigh bedroom set. color is a brownish \n",
      "qty 1 queen bed \n",
      "w 62 1/2 \n",
      "l 84 1/2 \n",
      "bed top piece 66” high \n",
      "bottom piece 32” high \n",
      "qty  ... is not in my Vocabulary!\n",
      "the word: $997 geoff lawton permaculture course, new never used. 18 dvd factory sealed set plus 6 bonus dvd's, and \"permaculture - a designers manual\" by bill mollison, new never used. is not in my Vocabulary!\n",
      "the word: i am selling seasonal farm bo is not in my Vocabulary!\n",
      "the word: 2008 hyundai engine 2.0l (non turbo) \n",
      "124k runs perfect is not in my Vocabulary!\n",
      "the word: vintage collection of board games \n",
      "some classics: \n",
      "carmen san diego (still sealed) \n",
      "trivial pursuit mastergame genius edition \n",
      "trivial pursuit baby boomer edition \n",
      "scrabble \n",
      "battleship \n",
      "yahtzee x2 \n",
      "great family fun \n",
      "$25 cash firm for all \n",
      "meet in seb ... is not in my Vocabulary!\n",
      "the word: it still has 1 year warranty on it bumper to bumper 2020 venom kpm200 | 200cc fuel-injected motorcycle | 6-speed i will te is not in my Vocabulary!\n",
      "the word: concrete pieces useful for retaining wall. appro is not in my Vocabulary!\n",
      "the word: t me \n",
      "i’m in vacaville \n",
      "ben is not in my Vocabulary!\n",
      "the word: mini fridge that’s more medium size. it does work but not always and i’m not good at fi is not in my Vocabulary!\n",
      "the word: stunning and rare!!! \n",
      "*2010 ferrari 599 gtb with full factory hgte package ($30k option) \n",
      "*rosso scuderia over nero interior \n",
      "*$368,900 original msrp \n",
      "*hgte (handling grand turismo evoluzione) package which includes upgraded springs; re-tuned transa is not in my Vocabulary!\n",
      "the word: offering coding services for bmw vehicles that allows owner to take full advantage of their intelligent vehicle. bmw's are powerful machines and they have the greatest tech, however, the settings for these are limited by bmw themselves. i can help yo ... is not in my Vocabulary!\n",
      "the word: used once in e is not in my Vocabulary!\n",
      "the word: ify heavy metals and chemicals from the body, including bpa. \n",
      "burn calories and lose weight. \n",
      "​speed healing of injuries  ... is not in my Vocabulary!\n",
      "the word: parting out a 2002 honda accord four-cylinder automatic. call for information and availability and pricing on parts. selling parts only. call 732-639-oo63. calls only is not in my Vocabulary!\n",
      "the word: full vehicle history report by autocheck. price is $10. just need your email and vin #. instant email delivery. is not in my Vocabulary!\n",
      "the word: 4 4runner the door code is a340h \n",
      "the torque converter and auto trans is included along with the transfer case. \n",
      "$100 or best reasonable offer. as is where is. \n",
      "i ... is not in my Vocabulary!\n",
      "the word: t 707.299.774nine \n",
      "thanks for looking at \n",
      "www.thecontainercity.com \n",
      "#storage \n",
      "#ship ... is not in my Vocabulary!\n",
      "the word: item specifics \n",
      "condition: seller refurbished: \n",
      "brand: lenovo \n",
      "ssd capacity: 120 gb ssd processor: intel core 2 duo \n",
      "features: 10/100 lan card, wi-fi model: lenovo thinkpad r60 \n",
      "color: black \n",
      "hard drive capacity: 120gb \n",
      "ram 2.5 gb \n",
      "most suitable for: ... is not in my Vocabulary!\n",
      "the word: 4 sale a 1989 freightliner 3 axle water truck ,air ride rears, cat 3406bw/ jake, 9 speed trans, 4000 gal stainless tank for potable water with stainless pump and plumbing, the truck is getting new rear drivers , the truck is in non op at this time an ... is not in my Vocabulary!\n",
      "the word:  - never used \n",
      "if you're looking for a e is not in my Vocabulary!\n",
      "the word: cellent masticating juicer. this is the one. \n",
      "tribest green star elite juicer \n",
      "more minerals in optimal bioavailability! \n",
      "bio-magnets have been integrated into the green star elite juicer's ... is not in my Vocabulary!\n",
      "the word: parting out a 2002 honda accord coupe 6 cylinder automatic. call for information and availability and pricing on parts. selling parts only. call 732-639-oo63. calls only is not in my Vocabulary!\n",
      "the word: little tikes perfect fit 4-in-1 trike \n",
      "this is used in good condition, there are some scuffs and scratches from normal use, see all my pic's for a better look \n",
      "the perfect fit 4-in-1 trike is ready to grow with your child! with all of the features of ... is not in my Vocabulary!\n",
      "the word: asking price is $550 (cash) \n",
      "delivery is possible at an additional fee ($25 flat fee) \n",
      "do you spend long hours at the desk? do you suffer from back or neck pain? are you constantly shifting your body in your current desk chair? you've got to try the  ... is not in my Vocabulary!\n",
      "the word: clean fill dirt $10 a yard delivered \n",
      "thousands of yards available \n",
      "call or te is not in my Vocabulary!\n",
      "the word: t \n",
      "469 \n",
      "two one five \n",
      "5206 is not in my Vocabulary!\n",
      "the word: , never used steel reinforced bed frame foundation w/upholstered grey head-board. \n",
      "see link below for item details. originally $249, on sale at amazon for $204 and being sold for $124. \n",
      "https://www.amazon.com/zinus-upholstered-stitched-pla ... is not in my Vocabulary!\n",
      "the error rate is:  0.6\n",
      "SF**SF**SF**SF**SF**SF**SF**SF**SF**SF**SF**SF**SF**SF**SF**SF**\n",
      "NY**NY**NY**NY**NY**NY**NY**NY**NY**NY**NY**NY**NY**NY**NY**NY**\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/lab466/anaconda3/lib/python3.6/re.py:212: FutureWarning: split() requires a non-empty pattern match.\n",
      "  return _compile(pattern, flags).split(string, maxsplit)\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#显示地域相关的词\n",
    "#def getTopWords(ny,sf):\n",
    "## \n",
    "##reload(bayes)\n",
    "## \n",
    "bayes.getTopWords(ny,sf)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
